package com.dlb.andorid.presenter;

import com.dlb.andorid.XAPI;
import com.dlb.andorid.XContract;
import com.dlb.andorid.XPresenter;
import com.dlb.andorid.XServerMsg;
import com.dlb.andorid.bean.ProductBean;
import com.dlb.andorid.bean.ServerResult;
import com.dlb.andorid.bean.SuperMarket;
import com.dlb.andorid.bean.SuperMarketType;

import java.util.HashMap;
import java.util.List;

public class SuperMarketPresenter extends XPresenter {

	XContract.ISuperMarketView iView;

	public SuperMarketPresenter(XContract.ISuperMarketView iView) {
		super(iView);
		this.iView = iView;
	}

	public void getSupermarket(long address_id){
		mModel.getSupermarket(address_id);
	}

	public void getSupermarketType(long supermarket_id){
		mModel.getSupermarketType(supermarket_id);
	}

	public void getSupermarketProduct(long supermarket_id, long supermarket_commodity_type, int page){
		mModel.getSupermarketProduct(supermarket_id, supermarket_commodity_type, page);
	}

	public void addCar(long id, String userId, int num, long typeId, float price) {
		mModel.addCar(id, userId, num, typeId, price);
	}

	@Override
	public void onDataSuccess(int vocational_id, HashMap<String, Object> exData, Object data) {
		super.onDataSuccess(vocational_id, exData, data);
		switch (vocational_id){

			case XAPI.GET_SUPERMARKET_VOCATIONAL_ID:
				iView.getSupermarketSuccess(((XServerMsg<SuperMarket>)data).getData());
				break;

			case XAPI.GET_SUPERMARKETTYPE_VOCATIONAL_ID:
				iView.getSupermarketTypeSuccess(((XServerMsg<List<SuperMarketType>>)data).getData());
				break;

			case XAPI.GET_SUPERMARKETPRODUCT_VOCATIONAL_ID:
				iView.getSupermarketProductSuccess(((XServerMsg<List<ProductBean>>)data).getData());
				break;

			case XAPI.ADD_CAR_VOCATIONAL_ID:
				iView.addCarSuccess(((XServerMsg<ServerResult>) data).getData());
				break;

		}

	}
}
